Crate route_recognizer

Source
Expand description

Recognizes URL patterns with support for dynamic and wildcard segments

§Examples

use route_recognizer::{Router, Params};

let mut router = Router::new();

router.add("/thomas", "Thomas".to_string());
router.add("/tom", "Tom".to_string());
router.add("/wycats", "Yehuda".to_string());

let m = router.recognize("/thomas").unwrap();

assert_eq!(m.handler().as_str(), "Thomas");
assert_eq!(m.params(), &Params::new());

§Routing params

The router supports four kinds of route segments:

  • segments: these are of the format /a/b.
  • params: these are of the format /a/:b.
  • named wildcards: these are of the format /a/*b.
  • unnamed wildcards: these are of the format /a/*.

The difference between a “named wildcard” and a “param” is how the matching rules apply. Given the router /a/:b, passing in /foo/bar/baz will not match because /baz has no counterpart in the router.

However if we define the route /a/*b and we pass /foo/bar/baz we end up with a named param "b" that contains the value "bar/baz". Wildcard routing rules are useful when you don’t know which routes may follow. The difference between “named” and “unnamed” wildcards is that the former will show up in Params, while the latter won’t.

Structs§

  • An iterator over Params.
  • The result of a successful match returned by Router::recognize.
  • Router parameters.
  • Recognizes URL patterns with support for dynamic and wildcard segments.